package CtrlLayer;
import ModelLayer.*;

import java.io.IOException;
import java.util.List;

public class OrderCtrl
{
	private OrderContainer OC;
	
	public OrderCtrl()
	{
		OC = OrderContainer.getInstance();
	}

	public void loadFromFile() throws IOException, ClassNotFoundException
	{
		OC.loadFromFile();
	}
	
	public void saveToFile() throws IOException
	{
		OC.saveToFile();
	}
	
	public void createSaleOrder(int ordernr, String date, double totalPrice, Employee employee, int deliveryDiscount, Customer customer, String deliveryDate, double offer)
	{
		SaleOrder mySaleOrder = new SaleOrder(ordernr, date, totalPrice, employee, deliveryDiscount, deliveryDate, customer, offer);
		OC.addSaleOrder(mySaleOrder);
	}
	
	public void createRentOrder(int ordernr, String date, double totalPrice, Employee employee, int deliveryDiscount, Customer customer, String recallDate)
	{
		RentOrder myRentOrder = new RentOrder(ordernr, date, totalPrice, employee, deliveryDiscount, customer, recallDate);
		OC.addRentOrder(myRentOrder);
	}
	
	public SaleOrder searchSaleOrder(int ordernr)
	{
		return OC.getSaleOrder(ordernr);
	}
	
	public RentOrder searchRentOrder(int ordernr)
	{
		return OC.getRentOrder(ordernr);
	}
	
	public void addPartOrder(int ordernr, int amount, SaleItem saleitem, RentItem rentItem, double subTotal, int quantityDiscount)
	{
		SaleOrder saleorder = searchSaleOrder(ordernr);
		PartOrder partorder = new PartOrder(amount, saleitem, rentItem, subTotal, quantityDiscount);
		saleorder.addPartOrder(partorder);
	}
	
	public List<SaleOrder> getSaleOrderList()
	{
		return OC.getOrderList();
	}
	
	public int getLOrder()
	{
		return OC.getLastOrder();
	}
	
	public void updateSO(int ordernr, String date, double totalPrice, Employee employee, int deliveryDiscount, Customer customer, String deliveryDate, double offer)
	{
		OC.updateSaleOrder(ordernr, date, totalPrice, employee, deliveryDiscount, customer, deliveryDate, offer);
	}
}
